package com.hk.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.hk.model.CustUserDto;
import com.hk.model.ICustUserService;

public class CustUserAddController extends MultiActionController {
	private ICustUserService custUserService;
	
	public void setCustUserService(ICustUserService custUserService) {
		this.custUserService = custUserService;
	}//
	public ModelAndView beforeCustAdd(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return new ModelAndView("custaddform");
	}//
	public ModelAndView custAdd(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id=request.getParameter("id");
		String name=request.getParameter("name");
		String address=request.getParameter("address");
		CustUserDto custdto=new CustUserDto();
		custdto.setId(id);
		custdto.setName(name);
		custdto.setAddress(address);
		int count=custUserService.custAdd(custdto);
		ModelAndView mav=new ModelAndView();
//		if(count>0){
//			mav.setViewName("redirect:/custuserlist.do");
//		}
		mav.setViewName("redirect:/custuserlist.do");
		return mav;
	}//
	public ModelAndView deleteCustUser(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id=request.getParameter("id");
		int count=custUserService.deleteCustUser(id);
		return new ModelAndView("redirect:/custuserlist.do");
	}//
	
	public ModelAndView deleteCustUsers(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String []ids=request.getParameterValues("delck");
		int count=custUserService.deleteCustUsers(ids);
		return new ModelAndView("redirect:/custuserlist.do");
	}//
}
